//
//  PTTabBarItemBtn.m
//  封装TableBar
//
//  Created by 贾旭周 on 15/12/11.
//  Copyright © 2015年 gm-iMac-iOS-03. All rights reserved.
//

#import "TPTabBarItemBtn.h"
#import "TPTabBarItem.h"
#define PTK_IMageViewSizeW 22
#define PTK_LabelViewSizeW
@implementation TPTabBarItemBtn

- (id) initWithFrame:(CGRect)frame
            withItem:(TPTabBarItem *)item
{
    self = [super initWithFrame:frame];
    if (self) {
        self.adjustsImageWhenHighlighted = NO;
        [self setBackgroundColor:[UIColor clearColor]];
        [self setImage:[UIImage imageNamed:item.normalImage]
              forState:UIControlStateNormal];
        [self setImage:[UIImage imageNamed:item.highlightedImage]
              forState:UIControlStateHighlighted];
        [self setImage:[UIImage imageNamed:item.highlightedImage]
              forState:UIControlStateSelected];

        if (item.title)
        {
            self.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
            self.contentVerticalAlignment = UIControlContentVerticalAlignmentTop;

            self.titleLabel.font = [UIFont systemFontOfSize:12];
            [self setTitle:item.title forState:UIControlStateNormal];
            [self setTitleColor:[UIColor grayColor]
                       forState:UIControlStateNormal];
            [self setTitleColor:[UIColor whiteColor]
                       forState:UIControlStateSelected];
            [self setTitleColor:[UIColor whiteColor]
                       forState:UIControlStateHighlighted];
            [self setImageEdgeInsets:UIEdgeInsetsMake(5, (self.frame.size.width - PTK_IMageViewSizeW)/2.0, 0, 0)];
            CGSize sizeText = [self.titleLabel.text sizeWithAttributes:@{NSFontAttributeName:self.titleLabel.font}];
            [self setTitleEdgeInsets:UIEdgeInsetsMake(PTK_IMageViewSizeW+10, (self.frame.size.width - sizeText.width)/2.0-PTK_IMageViewSizeW, 0, 0)];

        }
    }
    return self;
}

@end
